package 和为k的子数组;
//加入前缀
public class Solution2 {
    public int subarraySum(int[] nums, int k) {
        int len = nums.length;

        int count =0;
        int[] pre = new int[len+1];
        pre[0] = 0;

        for (int i = 0; i < len; i++) {
            pre[i+1] = pre[i] + nums[i];
        }

        for(int i = 0; i < len ; i++){
            for(int j=0 ; j < len ; j++){
                if(pre[j+1] - pre[i] == k)
                count++;
            }
        }
        return count;
    }
}
